const router = require('koa-router')();
const jwt = require('../utils/jwt.js')
const {findNoteListByType} = require('../controllers/index')
router.get('/findNoteListByType', jwt.verify(), async (ctx) => {
    //获取前端传递的note_type,去数据库中以该note_type字段读取数据,返回给前端
    const {note_type} = ctx.request.query

    try {
        const res = await findNoteListByType(note_type,ctx.userId)
        if (res.length) {
            ctx.body = {
                code: '8000',
                data: res,
                msg: '查询成功'
            }
        } else {
            ctx.body = {
                code: '8000',
                data: 'success',
                msg: '当前分类下没有数据'
            }
        }
    } catch (error) {
        ctx.body = {
            code: '8005',
            data: error,//不用打引号,因为error是object
            msg: '服务器异常'
        }
    }
})


module.exports = router